package com.zhuo.project.hms.service.impl;

import java.util.Date;
import java.util.List;

import com.zhuo.common.utils.DateUtils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zhuo.common.utils.SecurityUtils;
import com.zhuo.project.hms.mapper.ZzClinicMapper;
import com.zhuo.project.hms.domain.ZzClinic;
import com.zhuo.project.hms.service.IZzClinicService;

/**
 * 诊所信息Service业务层处理
 *
 * @author zhuo
 * @date 2020-03-20
 */
@Service
public class ZzClinicServiceImpl implements IZzClinicService {
    @Autowired
    private ZzClinicMapper zzClinicMapper;

    /**
     * 查询诊所信息
     *
     * @param id 诊所信息ID
     * @return 诊所信息
     */
    @Override
    public ZzClinic selectZzClinicById(Long id) {
        return zzClinicMapper.selectZzClinicById(id);
    }

    /**
     * 查询诊所信息列表
     *
     * @param zzClinic 诊所信息
     * @return 诊所信息
     */
    @Override
    public List<ZzClinic> selectZzClinicList(ZzClinic zzClinic) {
        return zzClinicMapper.selectZzClinicList(zzClinic);
    }

    /**
     * 新增诊所信息
     *
     * @param zzClinic 诊所信息
     * @return 结果
     */
    @Override
    public int insertZzClinic(ZzClinic zzClinic) {

        ZzClinic filter = new ZzClinic();
        filter.setClinicCode(zzClinic.getClinicCode());
        List<ZzClinic> filterList = zzClinicMapper.selectZzClinicList(filter);
        if (null != filterList && filterList.size() > 0) {
            Long id = filterList.get(0).getId();
            zzClinic.setId(id);
            zzClinic.setUpdateTime(new Date());
            zzClinic.setUpdateBy(SecurityUtils.getUsername());
            return zzClinicMapper.updateZzClinic(zzClinic);
        }
        zzClinic.setCreateBy(SecurityUtils.getUsername());
        zzClinic.setCreateTime(DateUtils.getNowDate());
        return zzClinicMapper.insertZzClinic(zzClinic);
    }

    /**
     * 修改诊所信息
     *
     * @param zzClinic 诊所信息
     * @return 结果
     */
    @Override
    public int updateZzClinic(ZzClinic zzClinic) {
        zzClinic.setUpdateTime(DateUtils.getNowDate());
        return zzClinicMapper.updateZzClinic(zzClinic);
    }

    /**
     * 批量删除诊所信息
     *
     * @param ids 需要删除的诊所信息ID
     * @return 结果
     */
    @Override
    public int deleteZzClinicByIds(Long[] ids) {
        return zzClinicMapper.deleteZzClinicByIds(ids);
    }

    /**
     * 删除诊所信息信息
     *
     * @param id 诊所信息ID
     * @return 结果
     */
    @Override
    public int deleteZzClinicById(Long id) {
        return zzClinicMapper.deleteZzClinicById(id);
    }
}
